/**
 * 跑马灯管理类;
 */
//var datamodel = cc.Class({
class MarqueeDataModel {
	marquee_list = [];
	isClose = false;
	marquee = null;
	isNeedRender = true;
	init(marquee) {
		this.marquee_list = [];
		this.isClose = false;

		this.marquee = marquee; //cc.vv.GLPageMgr.getItem("Marquee");
		if (!this.marquee) {
			console.log("marquee is not");
			return;
			//   cc.vv.GLPageMgr.openItem(
			//     "Marquee",
			//     function(page) {
			//       if (page) {
			//         console.log("_____11111111111");
			//         this.marquee = page;
			//         this.marquee.active(false);
			//       }
			//     }.bind(this)
			//   );
		}
	}

	/**
	 * 启动激活的选项;
	 * 在服务器未触发任何选项的时候,循环播放配置表中的;
	 */
	run() {
		if (this.isClose) {
			return;
		}
		// if (cc.vv.sceneName === "Login" || cc.vv.sceneName === "Hall") {
		// 	return;
		// }
		if (this.marquee_list.length <= 0) {
			return;
		}

		this.marquee = cc.vv.sceneMgr.getMarquee(); //cc.vv.GLPageMgr.getItem("Marquee");
		if (this.marquee) {
			if (this.marquee.Running()) {
				//正在运行中;
				return;
			}
			var msg = this.marquee_list.shift();
			this.marquee.run(msg, this.runEnd.bind(this));
		} else {
			console.log("marquee is not");
			return;
			//   cc.vv.GLPageMgr.openItem(
			//     "Marquee",
			//     function(page) {
			//       if (page) {
			//         this.marquee = page;
			//         var msg = this.marquee_list.shift();

			//         this.marquee.run(msg, this.runEnd.bind(this));
			//       }
			//     }.bind(this)
			//   );
		}
	}

	runEnd() {
		this.run();
	}

	setNeedRender(target) {
		this.isNeedRender = !!target;
		this.marquee.node.parent.active = !!target;
	}

	//获取是否需要截屏功能
	getNeedRender() {
		return this.isNeedRender;
	}

	//添加跑马灯数据;
	addMarquee(data) {
		if (this.isClose) {
			return;
		}
		console.log("_______marque Data = " + JSON.stringify(data));
		var dataSource = {
			msgType: data.msgType,
			content: "",
		};

		let _gameName = cc.vv.GLDefine.getChineseNameById(data.gameid);
		if (data.msgType == 1) {
			//系统跑马灯 change by tm
			// dataSource.content = "<color=#ffffff >" + data.sysMsg + "< /color>";
			dataSource.content = data.sysMsg ;
			this.marquee_list.push(dataSource);
			if (this.marquee_list.length > 1) {
				this.marquee_list.shift();
			}
			this.run();
		}
		return;
		// else if (data.msgType == 2) {
		// 	//坐庄
		// 	dataSource.content = "<color=#ffffff >" + "土豪" + "< /color>" +
		// 		"<color=#fcf77c >" + (data.rolename || "") + "< /color>" +
		// 		"<color=#ffffff >" + "坐庄" + "< /color>" +
		// 		"<color=#fcf77c >" + _gameName + "< /color>" +
		// 		"<color=#ffffff >" + "游戏，大家快去挑战吧。" + "< /color>";
		// } else if (data.msgType == 3) {
		// 	//牌型
		// 	dataSource.content = "<color=#ffffff >" + "恭喜" + "< /color>" +
		// 		"<color=#fcf77c >" + (data.rolename || "") + "< /color>" +
		// 		"<color=#ffffff >" + "在" + "< /color>" +
		// 		"<color=#fcf77c >" + _gameName + "< /color>" +
		// 		"<color=#ffffff >" + "中拿到" + "< /color>" +
		// 		"<color=#fcf77c >" + data.winType + "< /color>" +
		// 		"<color=#ffffff >" + "，赢得" + "< /color>" +
		// 		"<color=#fcf77c >" + data.winCoin / 100 + "< /color>" +
		// 		"<color=#ffffff >" + "，赚翻啦！" + "< /color>";
		// } else if (data.msgType == 4) {
		// 	//分数
		// 	dataSource.content = "<color=#ffffff >" + "恭喜" +
		// 		"<color=#fcf77c >" + (data.rolename || "") + "< /color>" +
		// 		"<color=#ffffff >" + "在" + "< /color>" +
		// 		"<color=#fcf77c >" + _gameName + "< /color>" +
		// 		"<color=#ffffff >" + "中赢得" + "< /color>" +
		// 		"<color=#fcf77c >" + data.winCoin / 100 + "< /color>" +
		// 		"<color=#ffffff >" + "，赚翻啦！" + "< /color>";
		// }
		// this.marquee_list.push(dataSource);
		// if (this.marquee_list.length > 1) {
		// 	this.marquee_list.shift();
		// }

		// this.run();
	}
	close() {
		if (this.marquee) {
			this.marquee.active(false);
		}
	}
	reset(name = "") {
		if (this.marquee) {
			this.marquee.active(false);
			this.marquee.reset(name);
		}
	}
}

export let marqueeDataModel: MarqueeDataModel = new MarqueeDataModel();
